import React from 'react';
import ReactDOM from 'react-dom';
import { Breadcrumb, Button } from 'antd';

const Index = React.createClass({
  contextTypes: {
    router: React.PropTypes.object
  },

  getInitialState() {
    return {
      item: '出租管理',
    }
  },
  
  handleRouter() {
    let path = this.props.location.pathname;
    let state = this.props.location.state;
    console.log(this.props.location.state)
    let lastPath = path.split('/')[path.split('/').length - 1];
    let index = '/landlord/rentManage/advanceOrder/list';
    let add = '/landlord/rentManage/advanceOrder/add';
    let goPathUrl = (lastPath == 'list' || lastPath == 'advanceOrder') ? add : index;
    this.context.router.push({pathname: goPathUrl,state: {...state}});
  },

  render () {
    let path = this.props.location.pathname;
    let detailData = this.state.detailData;
    console.log(detailData);
    let lastPath = path.split('/')[path.split('/').length - 1];
    console.log(lastPath)
    let routerItem = {
      'list': '预订单列表',
      'advanceOrder': '预订单列表',
      'add': '新增预订单',
      'cancle': '取消预订单',
      'modify': '修改预订单',
      'details': '预订单详情',

    };

    let txtName = ( lastPath == 'list' || lastPath == 'advanceOrder') ? '预订' : '返回';

    return (
      <div>
        <div className="nav-bar">
          <Breadcrumb separator="-" >
            <Breadcrumb.Item>{this.state.item}</Breadcrumb.Item>
            <Breadcrumb.Item>{routerItem[lastPath]}</Breadcrumb.Item>
          </Breadcrumb>
          { (lastPath !== 'list' && lastPath !== 'advanceOrder') ? <Button className="ant-button" type="primary" onClick={this.handleRouter}>{txtName}</Button> : null}
        </div>
        <div className="content-wrapper ">
          {this.props.children}
        </div>
      </div>
    );
  }
});

export default Index